<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>菜单管理-添加菜单</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" th:href="@{/layuimini/lib/layui-v2.6.3/css/layui.css}" media="all">
    <link rel="stylesheet" th:href="@{/layuimini/css/layuimini.css}" media="all">
    <link rel="stylesheet" th:href="@{/layuimini/css/public.css}" media="all">
    <link rel="stylesheet" th:href="@{/layuimini/lib/font-awesome-4.7.0/css/font-awesome.min.css}" media="all">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <div class="layui-form layuimini-form layui-form-pane" action="" lay-filter="menuForm">
            <input name="dictTypeId" type="hidden" th:value="${sysDict?.dictTypeId}"/>
            <div class="layui-form-item">
                <label class="layui-form-label required">字典编码</label>
                <div class="layui-input-block">
                    <input type="text" name="dictId" lay-verify="required" lay-reqtext="字典编码不能为空" placeholder="请输入字典编码" th:value="${sysDict?.dictId}" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">字典名称</label>
                <div class="layui-input-block">
                    <input type="text" name="dictName" lay-verify="required" lay-reqtext="字典名称不能为空" placeholder="请输入字典名称" th:value="${sysDict?.dictName}" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">其他编码</label>
                <div class="layui-input-block">
                    <input type="text" name="otherCode" placeholder="请输入字典名称" th:value="${sysDict?.otherCode}" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">排序码</label>
                <div class="layui-input-block">
                    <input type="number" min="0" name="dictSort" placeholder="请输入排序码" th:value="${sysDict != null ? sysDict.dictSort : '1'}" lay-verify="required" lay-reqtext="请输入排序码" class="layui-input">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">备注信息</label>
                <div class="layui-input-block">
                    <textarea name="remark" class="layui-textarea" placeholder="请输入备注信息" th:text="${sysDict?.remark}"></textarea>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-input-block">
                    <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">保存</button>
                </div>
            </div>
        </div>
    </div>
</div>

<script th:src="@{/layuimini/lib/layui-v2.6.3/layui.js}" charset="UTF-8"></script>
<script th:src="@{/layuimini/js/lay-config.js?v=1.0.4}" charset="UTF-8"></script>
<script type="text/javascript" th:inline="javascript">
    layui.use(['form','notice'], function () {
        let form = layui.form,
            notice = layui.notice,
            $ = layui.$;

        let ctxPath = /*[[@{/}]]*/'';
        let editFlag = [[${sysDict?.dictId}]] != null ? true : false;
        if(editFlag){
            $('input[name^="dictId"]').attr("disabled", true);    //修改时设置字典编码不允许改
        }

        //监听表单提交按钮
        form.on('submit(saveBtn)', function (data) {
            let url = ctxPath+'system/sysDict/saveDict';
            let type = 'POST';
            if(editFlag){
                url = ctxPath+'system/sysDict/updateDict';
                type = 'PUT';
            }
            $.ajax({
                type:type,
                url:url,
                data:JSON.stringify(data.field),
                contentType: 'application/json;charset=utf-8;',
                dataType:'json',
                success:function (res){
                    if(res.code === 200){
                        notice.success('操作成功');
                        setTimeout(function() {
                            layer.closeAll('iframe');
                            parent.location.reload();
                        },1000);
                    }else{
                        notice.error(res.msg);
                    }
                }
            });
            return false;
        });
    });
</script>
</body>
</html>
